package com.xiaobai.netease_news.activities;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xiaobai.netease_news.R;
import com.xiaobai.netease_news.views.CircleProgressBar;

public class OtherNewsActivity extends Activity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_other_news);

        RelativeLayout otherNewsHead = (RelativeLayout) findViewById(R.id.other_news_head);
        ImageView back = (ImageView) otherNewsHead.findViewById(R.id.news_detail_back);
        TextView replyCount = (TextView) otherNewsHead.findViewById(R.id.news_detail_reply_count);
        back.setOnClickListener(this);
        replyCount.setOnClickListener(this);

        final CircleProgressBar progressBar = (CircleProgressBar) findViewById(R.id.other_news_progress);
        progressBar.setMax(100);
        progressBar.setVisibility(View.VISIBLE);

        WebView otherNewsWeb = (WebView) findViewById(R.id.other_news_web);
        otherNewsWeb.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100)
                    progressBar.setVisibility(View.GONE);
            }
        });
        WebSettings settings = otherNewsWeb.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setLoadWithOverviewMode(true);
        settings.setUseWideViewPort(true);
        otherNewsWeb.loadUrl(getIntent().getStringExtra("url"));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.news_detail_back:
                finish();
                break;
            case R.id.news_detail_reply_count:
                // TODO 转跳评论页面
                break;
            case R.id.news_detail_more:
                break;
        }
    }
}
